package com.ys.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ys.exception.YsLjException;
import com.ys.exception.YsLjExceptionEnum;
import com.ys.model.dao.MaintainMapper;
import com.ys.model.dao.UserMapper;
import com.ys.model.pojo.Equipment;
import com.ys.model.pojo.Maintain;
import com.ys.model.pojo.User;
import com.ys.model.request.RepairSearchReq;
import com.ys.model.vo.IndexVo;
import com.ys.model.vo.MaintainDetailVo;
import com.ys.model.vo.SearchVo;
import com.ys.service.MaintainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;

@Service
public class MaintainServiceImpl implements MaintainService {
    @Autowired
    MaintainMapper maintainMapper;

    @Autowired
    UserMapper userMapper;


    /**
     *维护更新
     * @param maintain
     */
    @Override
    public void updateMaintain(Maintain maintain)
    {
        int count = userMapper.selectByUserName(maintain.getmPeopleName());
        if (count != 0)
        {
            maintain.setmPeopleId(count);
            maintainMapper.updateByPrimaryKeySelective(maintain);
        }else
        {
            throw new YsLjException(YsLjExceptionEnum.MAINTAIN_UPDATE_FAILED);
        }

    }



    @Override
    public void deleteMaintainById(Integer mId) {
        maintainMapper.deleteMaintainById(mId);
    }

    @Override
    public List<SearchVo> maintainSearchList() {
        return maintainMapper.maintainSearchList();
    }

    @Override
    public List<MaintainDetailVo> search(RepairSearchReq repairSearchReq) {
        List<MaintainDetailVo> maintainList =   maintainMapper.search(repairSearchReq);
        return maintainList;
    }

    @Override
    public int getMaintainId(Date date) {
        return maintainMapper.getMaintainId(date);
    }

    @Override
    public void maintainPictures(String pName, Integer pMId) {
        maintainMapper.maintainPictures(pName,pMId);
    }


}
